import http from '@/http'
import type {
  SingleConvertRequest,
  BatchConvertRequest,
  ValidateRequest,
  SingleConvertResponse,
  BatchConvertResponse,
  DefaultMappingResponse,
  ValidateResponse,
  BusinessRuleConvertRequest,
  BusinessRuleConvertResponse,
  BusinessRuleBatchConvertRequest,
  BusinessRuleBatchConvertResponse,
  BusinessRulesResponse
} from './type'

/**
 * Excel公式转换API
 */

// 转换单个Excel公式
export const convertSingleFormula = (data: SingleConvertRequest) => {
  return http.post<SingleConvertResponse>('/api/formula-convert/single', data)
}

// 批量转换Excel公式
export const convertBatchFormulas = (data: BatchConvertRequest) => {
  return http.post<BatchConvertResponse>('/api/formula-convert/batch', data)
}

// 获取默认的单元格变量映射模板
export const getDefaultMapping = () => {
  return http.get<DefaultMappingResponse>('/api/formula-convert/default-mapping')
}

// 验证转换后的公式
export const validateFormula = (data: ValidateRequest) => {
  return http.post<ValidateResponse>('/api/formula-convert/validate', data)
}

/**
 * 特殊业务规则转换API
 */

// 转换单个特殊公式为业务规则
export const convertBusinessRule = (data: BusinessRuleConvertRequest) => {
  return http.post<BusinessRuleConvertResponse>('/api/business-rule/convert', data)
}

// 批量转换特殊公式为业务规则
export const convertBatchBusinessRules = (data: BusinessRuleBatchConvertRequest) => {
  return http.post<BusinessRuleBatchConvertResponse>('/api/business-rule/convert/batch', data)
}

// 获取倍数规则
export const getBusinessRules = () => {
  return http.get<BusinessRulesResponse>('/api/business-rule/rules')
}

// 添加/更新倍数规则
export const updateBusinessRules = (data: Record<string, number[]>) => {
  return http.post('/api/business-rule/rules', data)
}

// 测试特殊公式转换
export const testSpecialFormula = (data: { formula: string }) => {
  return http.post('/api/business-rule/test', data)
}

/**
 * 电器公式转换API
 */

// 转换单个Excel公式为电器公式
export const convertSingleElectricalFormula = (data: { excelFormula: string }) => {
  return http.post('/electricalFormula/convert/single', data)
}

// 批量转换Excel公式为电器公式
export const convertBatchElectricalFormulas = (data: { excelFormulas: string[] }) => {
  return http.post('/electricalFormula/convert/batch', data)
}

// 获取电器公式转换示例
export const getElectricalFormulaExample = () => {
  return http.get('/electricalFormula/convert/example')
}

// 验证电器公式格式
export const validateElectricalFormula = (data: { formula: string }) => {
  return http.post('/electricalFormula/convert/validate', data)
} 